package com.whu.waterworks.util;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.dispatcher.mapper.ActionMapping;
import org.apache.struts2.dispatcher.mapper.DefaultActionMapper;

import com.opensymphony.xwork2.config.ConfigurationManager;

public class MyActionMapper extends DefaultActionMapper {
    //private static final String pathPrefix="";;
     @Override
    public ActionMapping getMapping(HttpServletRequest request,
    		ConfigurationManager configManager) {
    	String path = request.getRequestURI();
    	// path ="/Waterworks/pipeline/texture/station/getStationPic/2014202110087.png"
    	// ps[0]="";
    	// ps[1]="Waterworks";
    	// ps[2]="pipeline";
    	// ps[3]="texture";
    	// ps[4]="station";
    	// ps[5]="2014202110087.png"
    	if(path.startsWith("/Waterworks/pipeline/textureAction/")&&path.endsWith(".png"))
    	{
    		System.out.println("path"+"---->"+path);
    		ActionMapping mapping = new ActionMapping();
    		String[] ps = path.split("/");
    		mapping.setExtension("");
    		mapping.setName(ps[4]);
    		mapping.setNamespace("/gis");
    		Map<String,Object> params= new HashMap<>();
    		if(mapping.getName().equals("stationTexture"))
    		{
        		params.put("code", ps[5].substring(0,11));
    		}
    		else if(mapping.getName().equals("waterplantTexture"))
    		{
    			params.put("code", ps[5].substring(0,12));
    		}
    		mapping.setParams(params);
    		return mapping;
    	}
    	// TODO Auto-generated method stub
    	return null;
    }
}
